package timetracker.client.database;

import java.io.Serializable;

import javax.jdo.PersistenceManager;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;

import timetracker.client.ContragentService;
import timetracker.client.ContragentServiceAsync;
import timetracker.server.database.PMF;

@SuppressWarnings("serial")
@PersistenceCapable
public class Task implements Serializable{
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long key;
	
	@Persistent
	private String name;

	@Persistent
	private Long contragentKey;
	
	public Task(){
	}

	public Long getKey(){
		return key;
	}
	
	public String getName(){
		return name;
	}
	
	public void setName(String name){
		this.name = name;
	}

	public Long getContragentKey(){
		return contragentKey;
	}

	public void setContragentKey(Long contragentKey){
		this.contragentKey = contragentKey;
	}
	
	public void setContragent(Contragent contragent){
		if (contragent != null)
			this.contragentKey = contragent.getKey();
		else
			this.contragentKey = null;
	}
	
	/*public Contragent getContragent(){
		final Contragent contragent = null;
		final ContragentServiceAsync service = GWT.create(ContragentService.class);
		AsyncCallback<Contragent> callback = new AsyncCallback<Contragent>() {

			@Override
			public void onFailure(Throwable caught) {
				String details = caught.getMessage();
				Window.alert(details);
			}

			@Override
			public void onSuccess(Contragent retContragent) {
				//contragent = retContragent;
			}
		};
		
		service.getContragentById(contragentID, callback);
		
		return contragent;
	}
	
	public void setContragent(Contragent contragent){
		this.contragentID = contragent.getKey();
	}*/
	

}
